package com.wilmer.feedback.service.impl;

import java.util.List;

import com.wilmer.common.core.domain.entity.SysRole;
import com.wilmer.common.utils.DateUtils;
import com.wilmer.common.utils.SecurityUtils;
import com.wilmer.system.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wilmer.feedback.mapper.SysFeedbackMapper;
import com.wilmer.feedback.domain.SysFeedback;
import com.wilmer.feedback.service.ISysFeedbackService;

/**
 * 问题反馈Service业务层处理
 * 
 * @author Jett
 * @date 2024-05-20
 */
@Service
public class SysFeedbackServiceImpl implements ISysFeedbackService 
{
    @Autowired
    private SysFeedbackMapper sysFeedbackMapper;

    @Autowired
    private ISysRoleService roleService;

    public static final Integer MANGE_ROlE_ID = 4;

    public static final Integer PARENT_ROlE_ID = 5;
    /**
     * 查询问题反馈
     * 
     * @param id 问题反馈主键
     * @return 问题反馈
     */
    @Override
    public SysFeedback selectSysFeedbackById(Long id)
    {
        return sysFeedbackMapper.selectSysFeedbackById(id);
    }

    /**
     * 查询问题反馈列表
     * 
     * @param sysFeedback 问题反馈
     * @return 问题反馈
     */
    @Override
    public List<SysFeedback> selectSysFeedbackList(SysFeedback sysFeedback)
    {
        //查看用户的角色信息
        Integer roleId = roleService.userRoleIdByUserId(SecurityUtils.getUserId());
        if(roleId == PARENT_ROlE_ID){
            sysFeedback.setUserId(SecurityUtils.getUserId());
        } else if (roleId == MANGE_ROlE_ID) {
            sysFeedback.setDeptId(SecurityUtils.getDeptId());
        }
        return sysFeedbackMapper.selectSysFeedbackList(sysFeedback);
    }

    /**
     * 新增问题反馈
     * 
     * @param sysFeedback 问题反馈
     * @return 结果
     */
    @Override
    public int insertSysFeedback(SysFeedback sysFeedback)
    {
        sysFeedback.setUserId(SecurityUtils.getUserId());
        sysFeedback.setDeptId(SecurityUtils.getDeptId());
        //查看用户的角色信息
        Integer roleId = roleService.userRoleIdByUserId(SecurityUtils.getUserId());
        if(roleId == PARENT_ROlE_ID){
            sysFeedback.setUserType(1L);
        } else if (roleId == MANGE_ROlE_ID) {
            sysFeedback.setUserType(2L);
        }
        sysFeedback.setCreateTime(DateUtils.getNowDate());
        sysFeedbackMapper.insertSysFeedback(sysFeedback);
        Long feedbackId = sysFeedback.getId();
        //更新根问题ID
        sysFeedback.setId(feedbackId);
        sysFeedback.setRootId(feedbackId);
        sysFeedbackMapper.updateRootId(sysFeedback);
        return 1;
    }

    /**
     * 修改问题反馈
     * 
     * @param sysFeedback 问题反馈
     * @return 结果
     */
    @Override
    public int updateSysFeedback(SysFeedback sysFeedback)
    {
        return sysFeedbackMapper.updateSysFeedback(sysFeedback);
    }

    /**
     * 批量删除问题反馈
     * 
     * @param ids 需要删除的问题反馈主键
     * @return 结果
     */
    @Override
    public int deleteSysFeedbackByIds(Long[] ids)
    {
        return sysFeedbackMapper.deleteSysFeedbackByIds(ids);
    }

    /**
     * 删除问题反馈信息
     * 
     * @param id 问题反馈主键
     * @return 结果
     */
    @Override
    public int deleteSysFeedbackById(Long id)
    {
        return sysFeedbackMapper.deleteSysFeedbackById(id);
    }
}
